<template>
    <div class="full-screen-background">
        <!-- <h1> LOGIN </h1> -->
        <el-form label-width="70px" :inline="true" class="login-container" :model="form" :rules="rules">
            <h3 class="login-title">"漂流岛"系统管理员登录</h3>
            <el-form-item label="用户名" prop="adminUsername">
                <el-input v-model="form.adminUsername" placeholder="请输入用户名"></el-input>
            </el-form-item>

            <el-form-item label="密码" prop="adminPassword">
                <el-input  v-model="form.adminPassword" placeholder="请输入密码" type="password"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button class="login-button" type="primary" @click="submit">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import {adminLogin} from "../api/index"
export default {
    data(){
        return{
            form:{
                adminUsername:'',
                adminPassword:'',
            },
            rules:{
                adminUsername:[
                    {required:true,message:'请输入管理员用户名',trigger:'blur'}
                ],
                adminPassword:[
                    {required:true,message:'请输入管理员密码',trigger:'blur'}
                ]
            }
        }
    },
    methods:{
        submit(){
            adminLogin(this.form).then((ret)=>{
                console.log(ret)
                if(ret.data.code == 200){

                    //登录成功进入首页
                    localStorage.setItem('token', ret.data.data);
                    this.$router.push('/home')
                    //获取菜单

                }
                else{
                    this.$message({
                    type: 'error',
                    message: '用户名或密码不正确'
                    });       
                    this.form.adminPassword = ''
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
.full-screen-background {
  height: 100vh;
  background: linear-gradient(135deg, #7a8ce6, #e273e6);
  display: flex;
  justify-content: center;
  align-items: center;
}
.login-container{
    width: 350px;
    border: 1px solid #eaeaea;
    margin: 180px auto;
    padding: 35px 35px 15px 35px;
    background-color: #ffffff;
    border-radius: 15px;
    box-shadow: 0 0 25px #cac6c6;
    box-sizing: border-box;
    .login-title{
        text-align: center;
        margin-bottom: 40px;
        color: #505458
    }
    .el-input{
        width: 198px;
    }
    .login-button{
        margin-left: calc(50% + 50px);
        margin-top: 10px;
        // margin: 0 auto
        // margin-left: 106px;
    }
}
</style>
